library(survival)
#library(MASS)
foo = read.table('C:/Users/Mittal/Documents/Work/Code/survival-analysis/R/GENE_HD_R.txt',header=T,sep='\t')
#attach(foo)

#fit_cox = coxph(formula=Surv(y,censor)~Pro25G,data=foo)
#or
#fit_weibull = survreg(formula = Surv(y, 1 - censor)~Pro25G,data=foo,dist="weibull")

#scope = list(upper=paste('~',paste(names(foo),collapse='+')),lower=~1)
#fit_final = stepAIC(fit_cox,scope,direction="both")

#logLike = array(0,c(1,length(names(foo))-3))
p = 20
logLikeBest = array(-10000000000,p)
bestParam = array(-1,p)
for(k in 1:p)
{
	print(k)
	for(i in 1:24496)
	{
		if(i%%100 == 0)
		{
			print(i)
		}
		if(k == 1)
		{
			fit_pm = survreg(formula=Surv(y,censor)~foo[,i+2],data=foo,dist="exponential")
		}
		else
		{
			tempData = cbind(subData,foo[,i+2])
			fit_pm = survreg(formula=Surv(y,censor)~tempData,data=foo,dist="exponential")
		}
		logLike = fit_pm$loglik[2]
		if(logLike > logLikeBest[k])
		{
			logLikeBest[k] = logLike
			bestParam[k] = i+2
		}
		#logLike[i] = fit_pm$loglik[2];
	}
	if(k == 1)
	{
		subData = foo[,bestParam[k]]
	}
	else
	{
		subData = cbind(subData,foo[,bestParam[k]])
	}
}